home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / SCHED.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  16KB  |  517 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*           This module was originally written by Bob Hartman              */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                     BinkleyTerm Scheduler Routines                       */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50.  
  51. /**************************************************************************/
  52. /*** This MUST be exactly 16 total bytes including the terminating null ***/
  53. /*** or the routines read_sched() and write_sched() must be changed!!!! ***/
  54. /**************************************************************************/
  55. static char *BinkSched = PRDCT_SHRT "Schedule 08";      /* Version of scheduler   */
  56.  
  57.  
  58. void find_event ()
  59. {
  60.    time_t long_time;
  61.    struct tm *tm;
  62.    
  63.    int cur_day;
  64.    int our_time;
  65.    int i;
  66.    char cmds[150];
  67.  
  68.    BINK_EVENT evt;
  69.  
  70.    /* Get the current time into a structure */
  71.  
  72.    (void) time (&long_time);
  73.    tm = localtime (&long_time);
  74.  
  75.    cur_day = 1 << tm->tm_wday;
  76.  
  77.    our_time = (tm->tm_hour % 24) * 60 + (tm->tm_min % 60);
  78.  
  79.    cur_event = -1;
  80.  
  81.    if (tm->tm_mday != hist.which_day)
  82.       {
  83.       write_stats ();
  84.       (void) memset (&hist, 0, sizeof (HISTORY));
  85.       hist.which_day = tm->tm_mday;
  86.       if (un_attended && fullscreen)
  87.          {
  88.          do_today ();
  89.          sb_show ();
  90.          }
  91.       }
  92.  
  93.    /* Make the month 1-based instead of 0-based */
  94.    tm->tm_mon += 1;
  95.  
  96.    /* Go through the events from top to bottom */
  97.    for (i = 0; i < num_events; i++)
  98.       {
  99.       if (our_time >= e_ptrs[i].minute)
  100.          {
  101.          evt = e_ptrs[i];
  102.  
  103.          if ((cur_day & evt.days) &&
  104.              ((!evt.day) || (evt.day == (char)tm->tm_mday)) &&
  105.              ((!evt.month) || (evt.month == (char)tm->tm_mon)))
  106.             {
  107.             if (((our_time - evt.minute) < evt.length) ||
  108.             ((our_time == evt.minute) && (evt.length == 0)) ||
  109.             ((evt.behavior & MAT_FORCED) && (evt.last_ran != (char)tm->tm_mday)))
  110.                {
  111.                /* Are we not supposed to force old events */
  112.                if (((our_time - evt.minute) > evt.length) && (noforce))
  113.                   {
  114.                   e_ptrs[i].last_ran = (char) tm->tm_mday;
  115.                   continue;
  116.                   }
  117.  
  118.                if (evt.last_ran != (char) tm->tm_mday)
  119.                   {
  120.                   cur_event = i;
  121.                   do_ready (MSG_TXT(M_READY_WAITING));
  122.                   status_line (MSG_TXT(M_STARTING_EVENT), i + 1);
  123.  
  124.                   if (!blank_on_key)
  125.                      screen_blank = 0;
  126.  
  127.                   more_mail = 1;
  128.  
  129.                   /* Mark that this one is running */
  130.                   e_ptrs[i].last_ran = (char) tm->tm_mday;
  131.  
  132.                   /*
  133.                    * Mark that we have not yet skipped it. After all, it just
  134.                    * started! 
  135.                    */
  136.                   e_ptrs[i].behavior &= ~MAT_SKIP;
  137.  
  138.                   /* Write out the schedule */
  139.                   write_sched ();
  140.  
  141.                   /* If we are supposed to exit, then do it */
  142.                   if (evt.errlevel[0])
  143.                      {
  144.                      status_line (MSG_TXT(M_EVENT_EXIT), evt.errlevel[0]);
  145.  
  146.                      screen_blank = 0;
  147.                      errl_exit (evt.errlevel[0]);
  148.                      }
  149.                   else if (packer != NULL)
  150.                      {
  151.                      if (!blank_on_key)
  152.                         screen_blank = 0;
  153.                      status_line (MSG_TXT(M_CLEAN_PACK));
  154.                      mdm_init (modem_busy);
  155.                      exit_DTR ();
  156.                      screen_clear ();
  157.                      vfossil_cursor (1);
  158.                      if (cleanup != NULL)
  159.                         {
  160.                         (void) strcpy (cmds, cleanup);
  161.                         if (i >= 0)
  162.                            (void) strcat (cmds, evt.cmd);
  163.                         b_spawn (cmds);
  164.                         }
  165.                      (void) strcpy (cmds, packer);
  166.                      if (i >= 0)
  167.                         (void) strcat (cmds, evt.cmd);
  168.                      b_spawn (cmds);
  169.                      if (fullscreen)
  170.                         {
  171.                         screen_clear ();
  172.                         sb_dirty ();
  173.                         opening_banner ();
  174.                         mailer_banner ();
  175.                         }
  176.                      RAISE_DTR ();
  177.                      mdm_init (modem_init);
  178.                      status_line (MSG_TXT(M_AFTER_CLEAN_PACK));
  179.                      waitfor_line = timerset ((unsigned int)6000);
  180.                      }
  181.  
  182.                   cur_event = i;
  183.                   max_connects = evt.with_connect;
  184.                   max_noconnects = evt.no_connect;
  185.